home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / self / contrib.lha / contrib / xlib-support / xlib_glue.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-18  |  8.1 KB  |  255 lines

  1. /* Sun-$Revision: 8.1 $ */
  2.  
  3. # include <stdio.h>
  4. # include <X11/Xlib.h>
  5. # include <X11/Xutil.h>
  6. # include "_glueDefs.c.incl"
  7. # include "xlib.primMaker.h"
  8.  
  9. // Display_seal is declared here
  10. # include "xlibPrims.h"
  11.  
  12.  
  13. // Display_seal is defined in the VM
  14. # define xTypeSealsDo(template)                              \
  15.     template(Foo)                                                             \
  16.     template(Atom)                                                            \
  17.     template(Colormap)                                  \
  18.     template(Cursor)                                  \
  19.     template(Drawable)                                  \
  20.     template(Font)                                  \
  21.     template(GC)                                  \
  22.     template(Pixmap)                                  \
  23.     template(Screen)                                  \
  24.     template(Visual)                                  \
  25.     template(Window)                                  \
  26.     template(XAnyEvent)                                  \
  27.     template(XButtonEvent)                              \
  28.     template(XCharStruct)                              \
  29.     template(XClientMessageEvent)                          \
  30.     template(XColor)                                  \
  31.     template(XColormapEvent)                              \
  32.     template(XConfigureEvent)                              \
  33.     template(XCrossingEvent)                              \
  34.     template(XEnterWindowEvent)                              \
  35.     template(XEvent)                                  \
  36.     template(XExposeEvent)                              \
  37.     template(XFontStruct)                              \
  38.     template(XGCValues)                                  \
  39.     template(XGraphicsExposeEvent)                          \
  40.     template(XKeyEvent)                                  \
  41.     template(XImage)                                  \
  42.     template(XLeaveWindowEvent)                              \
  43.     template(XMapEvent)                                  \
  44.     template(XMotionEvent)                              \
  45.     template(XNoExposeEvent)                              \
  46.     template(XReparentEvent)                              \
  47.     template(XSizeHints)                              \
  48.     template(XTextProperty)                              \
  49.     template(XTextProperty_value)                          \
  50.     template(XUnmapEvent)                              \
  51.     template(XVisibilityEvent)                              \
  52.     template(XVisualInfo)                              \
  53.     template(XWMHints)
  54.  
  55. # define defineXTypeSeals(stem)                              \
  56.     char* CONC(stem,_seal) = STR(stem);
  57.  
  58. xTypeSealsDo(defineXTypeSeals)
  59.  
  60.  
  61. void XGetGCValues_wrap(Display* display, GC gc, unsigned long valuemask,
  62.                XGCValues *values_return, void* FH) {
  63.   int status = XGetGCValues(display, gc, valuemask, values_return);
  64.   if (status == 0) {
  65.     failure(FH, "XGetGCValues failed--valuemask may be invalid");
  66.   }
  67. }
  68.  
  69. int XSetWMProtocol_wrap(Display* display,  Window window,  Atom protocol) {
  70.   Atom ps[1];
  71.   ps[0] = protocol;
  72.   return XSetWMProtocols(display, window, ps, 1);
  73. }
  74.  
  75. void XQueryColors_wrap(Display* display,
  76.                Colormap colormap, 
  77.                objVectorOop colors_oop,
  78.                void *FH) {
  79.   XColor** pcolors = (XColor**)colors_oop->convertProxyArray(XColor_seal);
  80.   if (!pcolors) {
  81.     prim_failure(FH, BADTYPEERROR);
  82.     return;
  83.   }
  84.   int32 count = colors_oop->length();
  85.   XColor* colors = NEW_RESOURCE_ARRAY(XColor, count);
  86.   for (int32 i = 0;  i < count;  i++) {
  87.     colors[i] = *pcolors[i];
  88.   }
  89.   XQueryColors(display, colormap, colors, count);
  90.   for (i = 0; i < count; i++) {
  91.     *pcolors[i] = colors[i];
  92.   }
  93. }
  94.  
  95. void XStoreColors_wrap(Display* display, Colormap colormap, 
  96.                objVectorOop colors_oop, void *FH) {
  97.   XColor** pcolors = (XColor**)colors_oop->convertProxyArray(XColor_seal);
  98.   if (!pcolors) {
  99.     prim_failure(FH, BADTYPEERROR);
  100.     return;
  101.   }
  102.   int32 count = colors_oop->length();
  103.   XColor* colors = NEW_RESOURCE_ARRAY(XColor, count);
  104.   for (int32 i = 0; i < count; i++) {
  105.     colors[i] = *pcolors[i];
  106.   }
  107.   XStoreColors(display, colormap, colors, count);
  108. }
  109.  
  110. void XFillPolygon_wrap(Display* display, Drawable d, GC gc,
  111.                objVectorOop xsOop, objVectorOop ysOop,
  112.                int shape, int mode, void* FH) {
  113.   int32* xs = xsOop->convertIntArray();
  114.   int32* ys = ysOop->convertIntArray();
  115.   if (!xs || !ys) {
  116.     prim_failure(FH, BADTYPEERROR);
  117.     return;
  118.   }
  119.   int n = xsOop->length();
  120.   if (n != ysOop->length()) {
  121.     failure(FH, "different number of x and y coordinates");
  122.     return;
  123.   }
  124.   XPoint points[n];
  125.  
  126.   for (int i = 0; i < n; i++) {
  127.     points[i].x = xs[i];
  128.     points[i].y = ys[i];
  129.   }
  130.  
  131.   XFillPolygon(display, d, gc, points, n, Complex, CoordModeOrigin); 
  132. }
  133.  
  134. XFontStruct* XLoadQueryFont_wrap(Display* display, char* name, void* FH) {
  135.   XFontStruct* font_struct = XLoadQueryFont(display, name);
  136.   if (font_struct == NULL) {
  137.     failure(FH, "font does not exist");
  138.     return NULL;
  139.   }
  140.   return font_struct;
  141. }
  142.  
  143. Atom XClientMessageEvent_atomAt_wrap(XClientMessageEvent* rcvr,
  144.                      unsigned int index, void* FH) {
  145.   if (    sizeof(rcvr->data.l[0]) * index
  146.       >=  sizeof(rcvr->data.l)) {
  147.     prim_failure(FH, BADINDEXERROR);
  148.     return 0;
  149.   }
  150.   return rcvr->data.l[index];
  151. }
  152.  
  153. int XStringToTextProperty_wrap(XTextProperty* textProperty, char* string) {
  154.   return XStringListToTextProperty(&string, 1, textProperty);
  155. }
  156.  
  157. int XLookupString_wrap(XKeyEvent* event, char* string, int len) {
  158.   KeySym keysym;
  159.   XComposeStatus composeStatus;
  160.   int n = XLookupString(event, string, len, &keysym, &composeStatus);
  161.   return n;
  162. }
  163.  
  164. unsigned int XQueryBestStippleWidth(Display* display, Drawable which_screen,
  165.                     unsigned int width, unsigned int height,
  166.                     void* FH) {
  167.   unsigned int width_return, height_return;
  168.   if (!XQueryBestStipple(display, which_screen, width, height, &width_return,
  169.              &height_return)) {
  170.     prim_failure(FH, PRIMITIVEFAILEDERROR);
  171.     return 0;
  172.   }
  173.   return width_return;
  174. }
  175.  
  176. unsigned int XQueryBestStippleHeight(Display* display, Drawable which_screen,
  177.                      unsigned int width, unsigned int height,
  178.                      void* FH) {
  179.   unsigned int width_return, height_return;
  180.   if (!XQueryBestStipple(display, which_screen, width, height, &width_return,
  181.              &height_return)) {
  182.     prim_failure(FH, PRIMITIVEFAILEDERROR);
  183.     return 0;
  184.   }
  185.   return height_return;
  186. }
  187.  
  188. XVisualInfo* XMatchVisualInfo_wrap(Display* display, int screen, int depth,
  189.                    int vclass, void *FH) {
  190.   XVisualInfo* vinfo_return = new XVisualInfo;
  191.   if (!XMatchVisualInfo(display, screen, depth, vclass, vinfo_return)) {
  192.     delete vinfo_return;
  193.     failure(FH, "no matching visual found");
  194.     return NULL;
  195.   }
  196.   return vinfo_return;
  197. }
  198.  
  199. int maxCharHeight(XFontStruct* font_struct) {
  200.   return font_struct->max_bounds.ascent + font_struct->max_bounds.descent;
  201. }
  202. int maxCharWidth(XFontStruct* font_struct) {
  203.   return font_struct->max_bounds.width;
  204. }
  205.  
  206.  
  207. inline void XFree_XSizeHints_wrap(XSizeHints *p) {XFree((char*)p);}
  208. inline void XFree_XWMHints_wrap  (XWMHints   *p) {XFree((char*)p);}
  209.  
  210. inline XEvent* asXEvent(XEvent* e) {return e;}
  211.  
  212.  
  213. # define XEvent_member_wraps_Do(template)                      \
  214.     template(XAnyEvent,xany)                              \
  215.     template(XButtonEvent,xbutton)                          \
  216.     template(XCirculateEvent,xcirculate)                      \
  217.     template(XCirculateRequestEvent,xcirculaterequest)                  \
  218.     template(XClientMessageEvent,xclient)                      \
  219.     template(XColormapEvent,xcolormap)                          \
  220.     template(XConfigureEvent,xconfigure)                      \
  221.     template(XConfigureRequestEvent,xconfigurerequest)                  \
  222.     template(XCreateWindowEvent,xcreatewindow)                      \
  223.     template(XCrossingEvent,xcrossing)                          \
  224.     template(XDestroyWindowEvent,xdestroywindow)                  \
  225.     template(XErrorEvent,xerror)                          \
  226.     template(XExposeEvent,xexpose)                          \
  227.     template(XFocusChangeEvent,xfocus)                          \
  228.     template(XGraphicsExposeEvent,xgraphicsexpose)                  \
  229.     template(XGravityEvent,xgravity)                          \
  230.     template(XKeyEvent,xkey)                              \
  231.     template(XKeymapEvent,xkeymap)                          \
  232.     template(XMapEvent,xmap)                              \
  233.     template(XMapRequestEvent,xmaprequest)                      \
  234.     template(XMappingEvent,xmapping)                          \
  235.     template(XMotionEvent,xmotion)                          \
  236.     template(XNoExposeEvent,xnoexpose)                          \
  237.     template(XPropertyEvent,xproperty)                          \
  238.     template(XReparentEvent,xreparent)                          \
  239.     template(XResizeRequestEvent,xresizerequest)                  \
  240.     template(XSelectionClearEvent,xselectionclear)                  \
  241.     template(XSelectionEvent,xselection)                      \
  242.     template(XSelectionRequestEvent,xselectionrequest)                  \
  243.     template(XUnmapEvent,xunmap)                          \
  244.     template(XVisibilityEvent,xvisibility)
  245.  
  246. # define define_XEvent_member_wrap(type,member)                      \
  247.     type* CONC3(get_,member,_wrap) (XEvent* e) {return & e->member;}
  248.  
  249. XEvent_member_wraps_Do(define_XEvent_member_wrap)
  250.  
  251.  
  252. # define WHAT_GLUE FUNCTIONS
  253.     xlib_glue
  254. # undef WHAT_GLUE
  255.